package com.situ.vivamarket.controller.sys;

import com.situ.vivamarket.model.Member;
import com.situ.vivamarket.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/vm/sys/member")
public class MemberController {
    private  MemberService memberService;

    @Autowired
    public void setMemberService(MemberService memberService) {
        this.memberService = memberService;
    }

    /*
    * 跳转到列表页
    * */
    @GetMapping("/list")
    public String list() {
        return "sys/member/list";
    }
    @GetMapping("/add")
    public String add() {
        return "sys/member/add";
    }
    @GetMapping("/edit")
    public String edit(Integer id, Map<String, Object> map) {
        if (id == null) {
                map.put("error","修改的会员编号为空");
                return "sys/member/edit";
        }else{
            Member member = memberService.findById(id);
            if (member == null) {
                map.put("error","修改的会员为空");

                return "sys/member/edit";
            }else{

                map.put("member",member);
            }

        }
        return "sys/member/edit";
    }
}
